﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;



namespace DotNetNuke.Modules.UserDefinedTable
{


  public class EditBoolean : EditControl
  {


    private System.Web.UI.WebControls.CheckBox CheckBox;



    //public EditBoolean()
    //{
    //  base.Init += new EventHandler(this.EditBoolean_Init);
    //}




    protected override void OnInit(EventArgs e)
    {
      base.OnInit(e);
      //base.Init += new EventHandler(this.EditBoolean_Init);

      this.CheckBox = new System.Web.UI.WebControls.CheckBox();
      this.CheckBox.Style.Value = this.Style;
      this.CheckBox.ID = EditControl.CleanID(this.FieldTitle);
      this.ValueControl = this.CheckBox;
      this.Controls.Add(this.CheckBox);
      if (!string.IsNullOrEmpty(this.OutputSettings))
      {
        this.Controls.Add(new LiteralControl(string.Format(" {0}", this.OutputSettings)));
      }
      this.Value = this.DefaultValue;
    }




    //private void EditBoolean_Init(object sender, EventArgs evt)
    //{
    //  this.CheckBox = new System.Web.UI.WebControls.CheckBox();
    //  this.CheckBox.Style.Value = this.Style;
    //  this.CheckBox.ID = EditControl.CleanID(this.FieldTitle);
    //  this.ValueControl = this.CheckBox;
    //  this.Controls.Add(this.CheckBox);
    //  if (!string.IsNullOrEmpty(this.OutputSettings))
    //  {
    //    this.Controls.Add(new LiteralControl(string.Format(" {0}", this.OutputSettings)));
    //  }
    //  this.Value = this.DefaultValue;
    //}




    protected override bool IsNull()
    {
      return (bool.FalseString == this.Value);
    }




    public override string Value
    {
      get
      {
        return this.CheckBox.Checked.ToString();
      }
      set
      {
        value = value.ToLowerInvariant();
        this.CheckBox.Checked = (value.Equals("true", StringComparison.OrdinalIgnoreCase) || (value.Equals("on", StringComparison.OrdinalIgnoreCase)) || (value.Equals("yes", StringComparison.OrdinalIgnoreCase)));
      }
    }




  }

}

